package com.allen.retrofit2_rxjava2.activity;

import android.graphics.Rect;
import android.os.Build;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

import com.allen.retrofit2_rxjava2.R;
import com.allen.retrofit2_rxjava2.base.BaseActivity;
import com.allen.retrofit2_rxjava2.view.CenterRadioButton;
import com.allen.retrofit2_rxjava2.view.NoScrollViewPager;

import butterknife.BindView;

/**
 * Created by Administrator on 2019/8/9.
 */

public class FragmentActivity extends BaseActivity {
    /**
     * 主ViewPager，负责Fragment的切换
     */
    @BindView(R.id.main_gridview)
    NoScrollViewPager mainViewPager;

    /**
     *
     */
    @BindView(R.id.main_view_mplanet)
    CenterRadioButton mplanet;

    /**
     * 相册
     */
    @BindView(R.id.main_view_photo)
    CenterRadioButton photoAlbum;

    /**
     * 连接设备
     */
    @BindView(R.id.main_view_connect)
    CenterRadioButton connect;

    /**
     * 行程
     */
    @BindView(R.id.main_view_record)
    CenterRadioButton driverRecord;

    @Override
    public void init() {
        setContentView(R.layout.activity_fragment);
    }

    @Override
    public void data() {

    }

    public void setClickZoomEffect(final View view) {
        if (null != view) {
            view.setOnTouchListener(new View.OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    boolean cancelled = false;
                    Rect rect = new Rect();
                    switch (event.getAction()) {
                        case MotionEvent.ACTION_DOWN:
                            scaleTo(v, 1.2f);
                            break;

                        case MotionEvent.ACTION_MOVE:
                            if (rect.isEmpty()) {
                                v.getDrawingRect(rect);
                            }
                            if (!rect.contains((int) event.getX(), (int) event.getY())) {
                                scaleTo(v, 1);
                                cancelled = true;
                            }
                            break;

                        case MotionEvent.ACTION_UP:
                        case MotionEvent.ACTION_CANCEL:
                            if (!cancelled) {
                                scaleTo(v, 1);
                            } else {
                                cancelled = false;
                            }
                            break;

                    }

                    return false;
                }
            });
        }
    }

    public static void scaleTo(View v, float scale) {
        if (Build.VERSION.SDK_INT >= 11) {
            v.setScaleX(scale);
            v.setScaleY(scale);
        } else {
            float oldScale = 1;
            if (v.getTag(Integer.MIN_VALUE) != null) {
                oldScale = (Float) v.getTag(Integer.MIN_VALUE);
            }
            ViewGroup.LayoutParams params = v.getLayoutParams();
            params.width = (int) ((params.width / oldScale) * scale);
            params.height = (int) ((params.height / oldScale) * scale);
            v.setTag(Integer.MIN_VALUE, scale);
        }
    }
}